package aRole

import (
	"context"
	"github.com/jinzhu/copier"
	"t-go-zero/service/user/rpc/userclient"

	"t-go-zero/service/user/api/internal/svc"
	"t-go-zero/service/user/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ARoleInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewARoleInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ARoleInfoLogic {
	return &ARoleInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ARoleInfoLogic) ARoleInfo(req *types.ARoleInfoRequest) (resp *types.Response, err error) {

	res, err := l.svcCtx.UserRpc.ARoleFindOne(l.ctx, &userclient.ARoleFindOneReq{
		Id: req.Id, // 角色ID
	})
	if err != nil {
		return nil, err
	}

	var result ARoleFindOneResp
	_ = copier.Copy(&result, res)

	return &types.Response{
		Code: 0,
		Msg:  "成功",
		Data: result,
	}, nil
}

type ARoleFindOneResp struct {
	Id          int64  `json:"id"`           // 角色ID,
	Name        string `json:"name"`         // 角色名称,
	Remark      string `json:"remark"`       // 备注,
	CreatedName string `json:"created_name"` // 创建人,
	CreatedAt   int64  `json:"created_at"`   // 创建时间
}
